{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[sci butter filter - Remove DC offset w/ high sample rate](https://dsp.stackexchange.com/questions/72660/scipy-butter-filter-remove-dc-offset-w-high-sample-rate)\n",
    "\n",
    "I am having a hard time figuring out how to employ a high pass filter to remove the DC offset of my data signal with the \"scipy butter\" function because my sample rate is quite high. The crux of my issue seems to be that my sample rate Fs is very high and my cut off frequency is very low (ideally just the DC offset component, but could be 1 to 10Hz with a sample rate of 125ksps)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from scipy import signal\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "# inital parameters\n",
    "Fs = 125000         # sample rate (if changed to 125sps looks better)\n",
    "n = 9               # filter order\n",
    "Fc = 10             # cut off freq (Hz)\n",
    "Nyq = Fs/2.         # Nyquist freq (1/2 Fs)\n",
    "Fcc = float(Fc)/float(Nyq)  # normalized cut off freq\n",
    "\n",
    "\n",
    "# find butterworth xfer functions\n",
    "sos = signal.butter(n, Fcc, btype='hp', output='sos', analog=False)\n",
    "# find freq/mag\n",
    "w, h = signal.sosfreqz(sos, worN=1500, fs=Fs)\n",
    "#convert to log scale\n",
    "h_db = 20*np.log10(np.abs(h))\n",
    "\n",
    "# plot filter response\n",
    "fig1, ax1 = plt.subplots(1, 1)\n",
    "#ax1.plot(0.5*Fs*(w/np.pi), h_db)\n",
    "ax1.plot(w, h_db)\n",
    "ax1.set_title('db log')\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
